home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-03-06 | 4.1 KB | 85 lines | [TEXT/GEOL] |
- Item 0610592 22-Jan-90 12:41
-
- From: MADA2 MacApp Dev Assoc, Curtis Faith
-
- To: MACAPP.TECH$ MacApp Technical
-
- Sub: RE:TreeSaver virtual objs.
-
- Greg, Ed, Larry et al.,
-
- I have implemented a virtual object scheme of sorts in TreeSaver. I have an
- object that I call TNodeHandler that is responsible for maintaining, creating,
- storing, and retrieving nodes (TNode's).
-
- Each node represents a Thread, Text, or a Picture. I cannot fit all the nodes
- in memory and thus I need to be able to store them somewhere else.
-
- I use insideOut as a storage manager and thus can do all sorts of nifty
- searches and indexing while also being able to have multi-user access to the
- set of potential node objects.
-
- When a part of TreeSaver needs to get some node or list of nodes it makes a
- request to the TNodeHandler object. TNodeHandler returns the TNode's that meet
- the request. There are methods that return a TNode with a given ID (longint
- corresponding to InsideOut's Record ID), all the TNode's that have a parent of
- a given ID, all nodes with a date greater than a certain date and a certain
- type, and a few others.
-
- TNodeHandler has a LRU cache of at least n TNode's that it keeps in memory. It
- looks at the cache first for all requests. This has 2 benefits, it allows one
- to have quick access to TNode's that are frequently used, and it also allows
- one to have only one Object for a given disk object. If one merely retrieved
- the data from the disk and then created a TNode for it one might have 5 TNode
- objects each representing one specific node in the theoretical (disk)
- structure.
-
- This later point substantially facilitates having several different views with
- the same node in each of them. I keep a reference count for each of the
- objects and if one of the views changes some aspect of that object and its
- refCount is greater than 1, I send a TNodeChanged(changedNode: TNode); message
- to each of the views that contains nodes. There are several other advantages
- (besides reduced memory requirements) to having only one object that are a bit
- more complex to describe.
-
- The cache (a modified TList) will flush (essentially Free) any objects that
- have a refCount of 0 and are not among the n most recently used Objects. Thus
- one can have more than n objects in memory if they are all actually referenced.
-
- The cache is written out to disk when TreeSaver terminates and read in when it
- starts up, but the data is updated into the actual database whenever any
- changes are made, thus the cache never contains data that is newer than the
- database copy.
-
- Each Node contains a handle that represents the actual data, the text of the
- Threads, text or the PICT information. These are only read in when an action
- that requires the data itself is called for. Thus normally a TNode is not a
- large amount of data. For example one might have a list of TNodes that
- represent the most recent set of threads. Unless one needs to display the
- actual thread there is no need to keep the data for that thread in memory.
-
- The data is accessed via a call to GetNodeData a function which returns a
- Handle representing the data for the node. GetNodeData checks to see if the
- data field of the object is NIL in which case it will read it in and increment
- the dataRefCount field. The data is also automatically decompressed if it was
- compressed.
-
- A method FreeNodeData is called whenever a TNode no-longer needs to have its
- data in memory. This decrements the dataRefCount and Frees the data if it is
- 0.
-
- This scheme allows one to have a potentially unlimited number of TNode objects
- that can be accessed while not clogging up the memory manager with a lot of
- unused handles.
-
- The performance of the above scheme seems to be entirely satisfactory and can
- be improved with certain optimizations.
-
- I am writing an article which should appear in the next issue of FrameWorks
- about TreeSaver and its underlying data structures that will explain the above
- in more detail. I am also going to publish the source code for TreeSaver
- through the developers association.
-
- - Curtis
-
-